<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/taglib_include.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, target-densitydpi=medium-dpi, initial-scale=0.5, minimum-scale=0.5, maximum-scale=0.5, user-scalable=no" />
<meta content="yes" name="apple-mobile-web-app-capable" />
<meta content="black" name="apple-mobile-web-app-status-bar-style" />
<meta content="telephone=no" name="format-detection" />
<link href="${ctx}/css/main.css?ver=${main_css_version}" rel="stylesheet" type="text/css" />
<style type="text/css">
#main-top-right {
	background: none;
}
</style>
<title>${projectTitle }</title>
</head>
<body>
  <header id="main-top">
    <a href="${ctx}/trafficline/index.do?startCityId=${ticketQueryParam.startCityId}&starting=${ticketQueryParam.starting}&startStationId=${ticketQueryParam.startStationId}&arriveCityId=${ticketQueryParam.arriveCityId}&destination=${ticketQueryParam.destination }&arriveStationId=${ticketQueryParam.arriveStationId }&leaveDate=${ticketQueryParam.leaveDate}&startStationsDisabled=${ticketQueryParam.startStationsDisabled}&groupId=${ticketQueryParam.groupId}">
      <div id="main-top-left">
        <img src="${ctx}/images/mui_title_back_btn.png" class="img-2">
      </div>
    </a>
    <div id="main-top-title">${ticketQueryParam.starting }-${ticketQueryParam.destination }</div>
    <c:choose>
      <c:when test="${appVer == constant.appver_nc || appVer == constant.appver_ylns}">
        <a id="main-top-right" href="${ctx}/indexnc/index.do?ver=${appVer}">
          <img src="${ctx }/images/home_icon.png">
        </a>
      </c:when>
      <c:otherwise>
        <a id="main-top-right" href="${ctx}/trafficline/index.do?ver=${appVer}&startCityId=${ticketQueryParam.startCityId}&starting=${ticketQueryParam.starting}&startStationId=${ticketQueryParam.startStationId}&startStationsDisabled=${ticketQueryParam.startStationsDisabled}&groupId=${ticketQueryParam.groupId}">
          <img src="${ctx }/images/home_icon.png">
        </a>
      </c:otherwise>
    </c:choose>
  </header>
  <div id="container">
    <div id="container-date">
      <a href="${ctx}/trafficline/enquiry.do?startCityId=${ticketQueryParam.startCityId}&starting=${ticketQueryParam.starting}&startStationId=${ticketQueryParam.startStationId}&arriveCityId=${ticketQueryParam.arriveCityId}&destination=${ticketQueryParam.destination }&arriveStationId=${ticketQueryParam.arriveStationId }&leaveDate=${lastYMD}&startStationsDisabled=${ticketQueryParam.startStationsDisabled}&groupId=${ticketQueryParam.groupId}">
        <div id="container-date-back">
          <img src="${ctx}/images/hpe_title_back_btn.png" class="img-3">前一天
        </div>
      </a>
      <div id="container-date-select">${year }年${month }月${day }日 </div>
      <a href="${ctx}/trafficline/enquiry.do?startCityId=${ticketQueryParam.startCityId}&starting=${ticketQueryParam.starting}&startStationId=${ticketQueryParam.startStationId}&arriveCityId=${ticketQueryParam.arriveCityId}&destination=${ticketQueryParam.destination }&arriveStationId=${ticketQueryParam.arriveStationId }&leaveDate=${nextYMD}&startStationsDisabled=${ticketQueryParam.startStationsDisabled}&groupId=${ticketQueryParam.groupId}">
        <div id="container-date-next">
          后一天<img src="${ctx}/images/hpe_title_next_btn.png" class="img-3">
        </div>
      </a>
    </div>
    <div id="trains">
      <ul>
      <c:forEach var="trafficline" items="${trafficLineList }">
        <li isOnlySupportQuery="${cf:isOnlySupportQuery(trafficline.startStationId) }" surplusNum="${trafficline.surplusNum }" <c:if test="${trafficline.schType == constant.schType_fixed && trafficline.surplusNum == '0' }">style="background-color:rgb(239, 238, 238)"</c:if>>
          <form action="${ctx}/order/confirm.do" method="get">
            <div class="time">${trafficline.leaveTime }<c:if test="${trafficline.schType == constant.schType_serial }"><div style="font-size:16pt;">前有效</div></c:if></div>
            <div class="start-standing">${trafficline.startStationName }</div>
            <div class="Trains-type">${cf:schTypeName(trafficline.schType) }</div>
            <div class="price">
              <span>￥</span> ${trafficline.price }
            </div>
            <div class="arrive-standing">${trafficline.arriveStationName }</div>
            <c:if test="${trafficline.schType == constant.schType_fixed }">
              <c:if test="${trafficline.surplusNum != '0' }"><div class="votes">余票${trafficline.surplusNum }&nbsp;免票${trafficline.freeNum }</div></c:if>
              <c:if test="${trafficline.surplusNum == '0' }"><div class="votes">已售完</div></c:if>
            </c:if>
            <c:if test="${trafficline.schType == constant.schType_serial }">
              <div class="votes">余票充足</div>
            </c:if>
            <input type="hidden" name="regBusNo" value="${trafficline.regBusNo }"/>
            <input type="hidden" name="regBusNoFoid" value="${trafficline.regBusNoFoid }"/>
            <input type="hidden" name="price" value="${trafficline.price }" />
            <input type="hidden" name="halfPrice" value="${trafficline.halfPrice }"/>
            <input type="hidden" name="startStationId" value="${trafficline.startStationId }"/>
            <input type="hidden" name="arriveStationId" value="${trafficline.arriveStationId }"/>
            <input type="hidden" name="leaveDate" value="${trafficline.leaveDate }"/>
            <input type="hidden" name="leaveTime" value="${trafficline.leaveTime }"/>
            <input type="hidden" name="fullStationCharge" value="${trafficline.fullStationCharge }" />
            <input type="hidden" name="halfStationCharge" value="${trafficline.halfStationCharge }"/>
            <input type="hidden" name="schType" value="${trafficline.schType }"/>
            <input type="hidden" name="busTypeName" value="${trafficline.busTypeName }" />
            <input type="hidden" name="startStationName" value="${trafficline.startStationName }"/>
            <input type="hidden" name="arriveStationName" value="${trafficline.arriveStationName }"/>
            <input type="hidden" name="ticketQueryURL" value="${ctx}/trafficline/enquiry.do?startCityId=${ticketQueryParam.startCityId}&starting=${ticketQueryParam.starting}&startStationId=${ticketQueryParam.startStationId}&arriveCityId=${ticketQueryParam.arriveCityId}&destination=${ticketQueryParam.destination }&arriveStationId=${ticketQueryParam.arriveStationId }&leaveDate=${ticketQueryParam.leaveDate}&startStationsDisabled=${ticketQueryParam.startStationsDisabled}&groupId=${ticketQueryParam.groupId}"/>
            <input type="hidden" name="fullServicePrice" value="${trafficline.fullServicePrice }"/>
            <input type="hidden" name="halfServicePrice" value="${trafficline.halfServicePrice }"/>
            <input type="hidden" name="lineTypeId" value="${trafficline.lineTypeId }"/>
            <input type="hidden" name="surplusfreeNum" value="${trafficline.freeNum }"/>
            <input type="hidden" name="fullInsurance" value="${trafficline.fullInsurance }"/>
            <input type="hidden" name="halfInsurance" value="${trafficline.halfInsurance }"/>
            <input type="hidden" name="donatedInsurance" value="${trafficline.donatedInsurance}"/>
          </form>
        </li>
      </c:forEach>
      </ul>
    </div>
    <c:if test="${empty trafficLineList}">
       <div style="padding-top:15px;font-size:22pt;">
                 没有符合条件的记录！
       </div>
    </c:if>
  </div>
  <%@ include file="/WEB-INF/views/popup_alert.jsp"%>
  <script type="text/javascript" src="${ctx}/js/jquery.min.js?ver=${jquery_min_version}"></script>
  <!-- mergeTo:${ctx}/js/custom.min.js?ver=${custom_min_version} -->
  <script type="text/javascript" src="${ctx}/js/custom.js?ver=${custom_version}"></script>
  <!-- mergeTo -->
  <script type="text/javascript">
  $(document).ready(function() {
	  var constant_schTypeFixed = "${constant.schType_fixed}";// 固定班次常量
	  var nowtime = new Date("${now}");
	  var beforehandMinutes = 120; // 提前120分钟停止售票
	  var isNCStation = ${isNCStartStation};
	  var constant_startstationid_ay = "${constant.startstationid_ay}";
	  var isXIANStation = "${isXIANStation}";
	  var isZIYANGStation = "${isZIYANGStation}";
	  var isXUANHANStation = "${isXUANHANStation}";
	  var isJIANYANGStation = "${isJIANYANGStation}";
	  var isHeJiangYiYuanJieStation = "${isHeJiangYiYuanJieStation}";
	  var isBYStation = "${isBYStartStation}";
	  
	  var isBJKYZStation = "${isBJKYZStation}";

	  // 当代集团的车站提前30分钟停止售票
	  if (isNCStation) {
	      beforehandMinutes = 30;
	  } else if (constant_startstationid_ay == "${ticketQueryParam.startStationId}") { // 安岳车站提前20分钟停止售票
	      beforehandMinutes = 20;
	  } else if(isXIANStation == "true" || isHeJiangYiYuanJieStation == "true" || isBYStation == "true" || 
	          isBJKYZStation == "true"){
	      beforehandMinutes = 60;
	  } else if(isZIYANGStation == "true"){
	      beforehandMinutes = 30;
	  } else if(isXUANHANStation == "true"){
	      beforehandMinutes = 30;
	  } else if(isJIANYANGStation == "true"){
	      beforehandMinutes = 30;
	  }

	  // 把已过发车时间的条目置灰
	  $("li").each(function(i, obj) {
          var leaveDate = $(obj).find("input[name='leaveDate']").val();// 发车日期
          var leaveTime = $(obj).find("input[name='leaveTime']").val();// 发车时间
          var departureTimestr = leaveDate + " " + leaveTime;
          var departureTime = new Date(departureTimestr.replace("-", "/").replace("-", "/"));

          departureTime.setMinutes(departureTime.getMinutes() - beforehandMinutes, departureTime.getSeconds(), 0);
          if (departureTime < nowtime) {
        	  $(obj).css("background-color","rgb(239, 238, 238)");
        	  $(obj).find("div[class='price']").after("<div class='stoppedSaleHint'>已停售</div>");
        	  $(obj).find("div[class='arrive-standing']").css("margin-left","10%");
          }
	  });
	  // 给每条班次信息的li绑定事件处理
      $("li").on("click", function(e) {
          if ($(this).attr("isOnlySupportQuery") == 'true') {// 是否只支持车次查询
              openAlert("您所选班次暂不支持购票！");
          } else {
              var leaveDate = $(this).find("input[name='leaveDate']").val();// 发车日期
              var leaveTime = $(this).find("input[name='leaveTime']").val();// 发车时间
              var schType = $(this).find("input[name='schType']").val(); // 班次类别
              var surplusNum = $(this).attr("surplusNum"); // 余票数
              var departureTimestr = leaveDate + " " + leaveTime;
              var departureTime = new Date(departureTimestr.replace("-", "/").replace("-", "/"));

              departureTime.setMinutes(departureTime.getMinutes() - beforehandMinutes, departureTime.getSeconds(), 0);
              if (departureTime < nowtime) {
                  if (isNCStation) {
                      openAlert("您所选班次应提前30分钟购票，请重新选择！");
                  } else if(constant_startstationid_ay == "${ticketQueryParam.startStationId}") {
                      openAlert("您所选班次应提前20分钟购票，请重新选择！");
                  } else if(isXIANStation == "true" || isHeJiangYiYuanJieStation == "true" || isBYStation == "true" || 
                          isBJKYZStation == "true"){
                      openAlert("您所选班次应提前1小时购票，请重新选择！");
                  } else if(isZIYANGStation == "true"){
                      openAlert("您所选班次应提前30分钟购票，请重新选择！");
                  } else if(isXUANHANStation == "true"){
                      openAlert("您所选班次应提前30分钟购票，请重新选择！");
                  } else if(isJIANYANGStation == "true"){
                      openAlert("您所选班次应提前30分钟购票，请重新选择！");
                  } else {
                      openAlert("您所选班次应提前2小时购票，请重新选择！");
                  }
                  return false;
              } else if (schType == constant_schTypeFixed && surplusNum == '0') {
                  openAlert("您所选班次车票已售完，请选择其他班次");
                  return false;
              }

              $(this).children().submit();
          }
      });
  });
  </script>
</body>
</html>
